package cn.tfyhyc.springcloud.service.impl;

import cn.tfyhyc.springcloud.service.IMessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;
import java.util.UUID;

@Slf4j
@EnableBinding(Source.class) // 定义消息的推出管道
public class IMessageProviderImpl implements IMessageProvider {

    @Resource(name = "output")
    private MessageChannel output; // 消息发送管道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        // 构建一个消息
        Message<String> build = MessageBuilder.withPayload(serial).build();
        output.send(build);
        log.info("********************************* serial:" + serial);
        return serial;
    }
}
